import re

sws = {}
sw = {}
curr_sw = None
begin_groups = False

for line in open('D:/exp-data/ibdiagnet2/ibdiagnet2/ibdiagnet2.far'):
    if line.startswith('Switch'):
        if curr_sw:
            sws[curr_sw['guid']] = curr_sw
        guid = re.search(r"0x([0-9a-f]+)", line).group(1)
        curr_sw = {
            'guid': guid,
            'groups': {}
        }
        
    elif begin_groups:
        if not line.strip():
            begin_groups = False
            continue
        
        items = line.split()
        if len(items) == 4:
            curr_sw['groups'][items[0]] = items[3].split(',')[:-1]
        else:
            curr_sw['groups'][items[0]] = []
        
    elif line.startswith('---') and len(line) == 75:
        begin_groups = True
        
    elif line.startswith('LFT'):
        begin_groups = False
    
    if (len(sws) > 0):
        break
        
print(sws)
print(len(sws))
